/**
 * Created by yongmingwei on 16/10/28.
 */
import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    Platform,
    Switch,
    Image
} from 'react-native';

var Dimensions = require('Dimensions');
var {width,height} = Dimensions.get('window');
var CommonCell = React.createClass({
    getDefaultProps(){
        return{
            title:'',//标题
            isSwitch:false,
            rightTitle:''
        }
    },
    getInitialState(){
        return{
            isOn:false,
        }
    },
    render() {
        return (
            <TouchableOpacity>
                <View style={styles.container}>
                    <Text style={{marginLeft:8}}>
                        {this.props.title}
                    </Text>
                    {this.renderRightView()}
                </View>
            </TouchableOpacity>
        );
    },
    renderRightView(){
        if(this.props.isSwitch) {
            return (
                <Switch value={this.state.isOn == true} onValueChange={()=>{this.setState({isOn:!this.isOn})}}
                        style={{marginRight:8}}>

                </Switch>
            )
        }else {
            return(
                <View style={{flexDirection:'row', alignItems:'center'}}>
                    {this.rightTitle()}
                    <Image source={{uri:'icon_cell_rightArrow'}} style={{width:8,height:13,marginRight:8}}></Image>
                </View>
            )
        }
    },
    rightTitle(){
        if (this.props.rightTitle.length > 0){
            return(
                <Text style={{color:'gray',marginRight:3}}>{this.props.rightTitle}</Text>
            )
        }
    }
});


const styles = StyleSheet.create({
    container: {
        height:Platform.OS == 'ios'?40:30,
        width:width,
        backgroundColor:'white',
        borderBottomColor:'#dddddd',
        borderBottomWidth:0.5,

        flexDirection:'row',
        justifyContent:'space-between',
        alignItems:'center'
    }
});

module.exports = CommonCell;